package gui.search;

import java.util.List;

import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import Model.Pet;;

public class PetSearchPane extends JPanel {

	private static final long serialVersionUID = 1L;
	
	private JTable table;
	private DefaultTableModel model;
	private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
	public static PetSearchPane instance;
	
    public static PetSearchPane getInstance(){
    	if(instance==null){
    		instance= new PetSearchPane();
    	}
		return instance;    		    	    	   
    }
    
    
    @SuppressWarnings("serial")
	public PetSearchPane(){
    	jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        model = new javax.swing.table.DefaultTableModel(
                new Object [][] {}, new String [] {"Name", "Species", "Age", "Weight", "Picture"}) {
    			@SuppressWarnings("rawtypes")
    			Class[] types = new Class [] {
                    java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.Float.class, java.lang.String.class
                };
                @SuppressWarnings({ "unchecked", "rawtypes" })
    			public Class getColumnClass(int columnIndex) {
                    return types [columnIndex];
                }
            };
        jTable1.setModel(model);
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(2).setMaxWidth(50);
        jTable1.getColumnModel().getColumn(3).setMaxWidth(100);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
        );
    }
    
    public void fillTable(List<Pet> pets){
		int rows = model.getRowCount();
		for(int i=0; i < model.getRowCount(); i++)
			model.removeRow(0);
		for ( Pet p : pets)
		{
		    model.addRow(new Object[] {p.getName(),p.getSpecies(),p.getAge(),p.getWeight(),p.getPicture()});
		}
		
	}
    
}
